<!DOCTYPE html>
<html>
<head>
    <title>我的游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>

    <script>
        $(function () {
            // 从sessionStorage中获取当前登录用户的信息
            var user = JSON.parse(sessionStorage.getItem("user"));
            $(".nickName").html(user.nickName)
            //获取装载数据的input框
            var currentInput = $("#currentPage");
            //用于存储游记的数组容器
            var travelArr = [];
            //总页数
            var pages = 1;
            //当前页为第一页
            currentInput.val(1);

            //获取游记数据的方法
            function query() {
                //获取当前页的值
                var currentPage = currentInput.val();//1
                $.get('/systemMessages', {currentPage: currentPage}, function (data) {
                    //合并两个数组到第一个参数数组上
                    console.log(data);
                    $.merge(travelArr, data.list);
                    //用于渲染时循环,循环时是取list的属性出来
                    var json = {
                        list: travelArr
                    };
                    //渲染数据
                    $("#smaller").renderValues(json,{getHref: getHref,getState:function (item, value) {
                            if(value){
                                $(item).html('未读')
                            }else {
                                $(item).html('已读')
                            }
                        }});
                    //设置总页数
                    pages = data.pages;
                });
                //当前页input框+1
                currentInput.val(parseInt(currentPage) + 1);
            }

            //默认查询第一页的数据
            query();

            //当页面滚动条变化时，执行的函数
            $(window).scroll(function () {
                if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
                    var currentPage = currentInput.val();
                    //判断是否小于或等于最后一页,如果是就去查询
                    if (currentPage <= pages) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '已经到底了!',
                            autoClose: 500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });
        });
    </script>
</head>


<body>
<input type="hidden" name="currentPage" id="currentPage" value="1">
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:window.history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>系统消息</span>
        </div>
        <div class="col"></div>
    </div>
</div>
<div id="smaller">
    尊敬的 <span class="nickName" style="font-size: 34px;"></span>，您有未读的系统消息
    <hr>
    <div id="dailyCommends2" render-loop="list">

        <div >
            您的<a  style="font-size: 18px;color: #6f42c1" data-href="editTravels.html?states=true&id=" render-key="list.travel.id" render-fun="getHref">
            《<span render-html="list.travel.title"></span>》</a><br>
            <div>
                <span render-html="list.content" style="font-size: 18px;"></span>
            </div>
                <span render-key="list.state" render-fun="getState"></span>
            <hr>
        </div>
    </div>

</div>

</body>
</html>
